package com.leoandroid.tool.toolsbox.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.leoandroid.tool.toolsbox.largeread.R
import com.leoandroid.tool.toolsbox.largeread.databinding.AdapterZodiacBinding

class ZodiacAdapter(val context: Context,val list:ArrayList<String>): RecyclerView.Adapter<ZodiacAdapter.Holder>() {

    val iconList = listOf(R.mipmap.s_laoshu,R.mipmap.s_niu,R.mipmap.s_laohu,R.mipmap.s_tuzi,R.mipmap.s_long,R.mipmap.s_she,R.mipmap.s_ma,R.mipmap.s_yang,R.mipmap.s_houzi,R.mipmap.s_ji,R.mipmap.s_gou,R.mipmap.s_zhu)
    inner class Holder(itemView: View):RecyclerView.ViewHolder(itemView)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
        val inflater = DataBindingUtil.inflate<AdapterZodiacBinding>(LayoutInflater.from(context),R.layout.adapter_zodiac,parent,false)
        return Holder(inflater.root)
    }

    override fun onBindViewHolder(holder: Holder, position: Int) {
        val dataBind:AdapterZodiacBinding?=DataBindingUtil.getBinding(holder.itemView)
        dataBind?.apply {
            nameTv.text = list[position]
//            val drawable = iconList[position].toDrawable()
//            drawable.setBounds(0,0,drawable.minimumWidth,drawable.minimumHeight)
//            nameTv.setCompoundDrawables(null,null,drawable,null)
//            imageview.setImageResource(iconList[position])
            rootCl.setOnClickListener {
                val intent = Intent(context, com.leoandroid.tool.toolsbox.ChineseZodiacDetailsActivity::class.java)
                intent.putExtra("KEY",list[position])
                context.startActivity(intent)
            }
        }
    }

    override fun getItemCount(): Int {
       return list.size
    }
}